package com.lablzh.gdxy.repository.design;

import com.lablzh.gdxy.entity.design.Design;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;


public interface DesignRepository extends JpaRepository<Design,Integer> {

    List<Design> findAllByAudit(String audit,Sort sort);

    Page<Design> findAllByAudit(String audit, Pageable pageable);

    List<Design> findAllByTeacherUsername(String username, Sort sort);
    @Modifying
    @Transactional
    @Query("update Design set status=?2 where id=?1")
    int  updateStatusById(Integer id,String status);
    @Modifying
    @Transactional
    @Query("update Design set audit=?2 where id=?1")
    int updateAuditById(Integer id, String audit);

//    List<Design> findAllByCollegeAndMajorAndGrade(String college, String major, String grade);

    @Modifying
    @Transactional
    @Query("update Design set applyed=?2 where id=?1")
    void updateApplyedById(Integer id, int i);

    @Modifying
    @Transactional
    @Query("update Design set recv=?2 where id=?1")
    void updateRecvById(Integer id, int i);

    @Modifying
    @Transactional
    @Query("update Design set reportToReview=?2,reportReviewed=?3 where id=?1")
    void updateReportToReviewAndReportReviewedById(Integer id, int i, int i1);

    @Modifying
    @Transactional
    @Query("update Design set transToReview=?2,transReviewed=?3 where id=?1")
    void updateTransToReviewAndTransReviewedById(Integer id, int i, int i1);

    @Modifying
    @Transactional
    @Query("update Design set paperToReview=?2,paperReviewed=?3 where id=?1")
    void updatePaperToReviewAndPaperReviewedById(Integer id, int i, int i1);

    @Modifying
    @Transactional
    @Query("update Design set reportToSummit=?2,reportSummited=?3, reportToReview=?4 where id=?1")
    void updateReportToSummitAndReportSummitedAndReportToReviewById(Integer id, int i, int i1, int toReview);

    @Modifying
    @Transactional
    @Query("update Design set transToSummit=?2,transSummited=?3, transToReview=?4 where id=?1")
    void updateTransToSummitAndTransSummitedAndTransToReviewById(Integer id, int i, int i1,int toReview);

    @Modifying
    @Transactional
    @Query("update Design set paperToSummit=?2,paperSummited=?3, paperReviewed=?4 where id=?1")
    void updatePaperToSummitAndPaperSummitedAndPaperToReviewById(Integer id, int i, int i1, int toReview);

    List<Design> findAllByCollegeAndGrade(String college, String grade);


    Design findByName(String name);

    @Modifying
    @Transactional
    @Query("update Design set transToSummit=?2,reportToSummit=?3,paperToSummit=?4,transToReview=?5,reportToReview=?6,paperToReview=?7 where id=?1")
    void updateTransToSummitAndReportToSummitAndPaperToSummitAndTransToReviewAndReportToReviewAndPaperToReviewById(Integer id, int tts, int rts, int pts, int ttr, int rtr, int ptr);


    @Modifying
    @Transactional
    @Query("update Design set task=?2 where id=?1")
    void updateTaskByID(Integer id, String filename);

    @Modifying
    @Transactional
    @Query("update Design set taskAudit=?2 where id=?1")
    void updatetaskAuditByID(Integer id, String taskAudit);
}
